export const initHelper = (parent, cloneNode, fromNode) => {
  if (!parent || !cloneNode || !fromNode) return null;
  const cloneRef = parent.appendChild(cloneNode);
  const nodeRect = fromNode.getBoundingClientRect();
  cloneRef.style.position = 'fixed';
  cloneRef.style.zIndex = 10000;
  cloneRef.style.top = `${nodeRect.top}px`;
  cloneRef.style.left = `${nodeRect.left}px`;
  cloneRef.style.width = `${nodeRect.width}px`;
  cloneRef.style.height = `${nodeRect.height}px`;
  cloneRef.style.backgroundColor = `#155bd4`;
  return cloneRef;
};
export const removeNode = (node) => {
  if (node?.parentElement !== null) {
    node.parentElement.removeChild(node);
  }
};
export const getCurrent = (node, id) => {
  if (!node) return null;
  if (node.dataset?.id === id) {
    return node;
  }
  const parent = node.parentElement;
  const current = getCurrent(parent);

  return current;
};
export function throttle(fn, delay = 16.66) {
  let flag = true;
  return (...args) => {
    if (!flag) {
      return null;
    }
    flag = false;
    setTimeout(() => {
      fn.apply(this, args);
      flag = true;
    }, delay);
  };
}
export function uuid() {
  function S4() {
    return ((1 + Math.random()) * 0x10000 || 0).toString(16).substring(1);
  }
  const str = `${S4() + S4()}-${S4()}-${S4()}-${S4()}-${S4()}${S4()}${S4()}`;
  return str;
}
